<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='姓名'>
              <a-input placeholder='请输入姓名' v-model='queryParam.name'></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="部门">
              <j-dict-select-tag placeholder="请选择部门" v-model="queryParam.auditGrade" dictCode="audit_grade"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="6" :md="8" :sm="12">
              <a-form-item label="申请月份">
                <j-date
                  placeholder="请选择开始时间"
                  class="query-group-cust"
                  v-model="queryParam.salaryTime_begin"
                ></j-date>
                <span class="query-group-split-cust"></span>
                <j-date
                  placeholder="请选择结束时间"
                  class="query-group-cust"
                  v-model="queryParam.salaryTime_end"
                ></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('工资-汇总')">导出</a-button>
<!--      <a-button @click='handleBpm' type='primary' icon='plus'>发起流程</a-button>-->
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button @click='handleCount' type='primary' icon='plus'>汇总</a-button>
      <!-- 高级查询区域 -->
<!--      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">


        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->
               <a @click="handleDetail(record)">详情</a>

<!--          <a-divider type="vertical" />-->
          <a-dropdown>
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--           -->
<!--              </a-menu-item>-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <hf-wage-salary-count-modal ref="modalForm" @ok="modalFormOk"></hf-wage-salary-count-modal>
    <j-modal
      :title='countTitle'
      :width='400'
      :visible='countVisible'
      @ok='handleCountOk'
      @cancel='handleCountCancel'
      cancelText='关闭'>
      <div >
        <span>选择月份：</span>
        <a-month-picker style='width: calc(100% - 70px)' placeholder='请选择月份' @change='monthChange' />
      </div>
    </j-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HfWageSalaryCountModal from './modules/HfWageSalaryCountModal'
  import { splitByNum } from '@/utils/util'
  import moment from 'moment'
  import { getAction } from '@api/manage'

  export default {
    name: 'HfWageSalaryCountList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HfWageSalaryCountModal
    },
    data () {
      return {
        description: '工资-汇总管理页面',
        countTitle: '汇总',
        countVisible: false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'日期',
            align:"center",
            dataIndex: 'salaryTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'部门',
            align:"center",
            dataIndex: 'auditGrade_dictText'
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title: '应出勤天数',
            align: 'center',
            dataIndex: 'attendanceDay',
          },
          {
            title: '实际出勤天数',
            align: 'center',
            dataIndex: 'actualAttendanceDay',
          },
          {
            title: '报工天数',
            align: 'center',
            dataIndex: 'workDay',
          },
          {
            title:'税前工资',
            align:"center",
            dataIndex: 'salaryBeforeTax',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'合同工资',
            align:"center",
            dataIndex: 'contractSalary',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'岗位工资',
            align:"center",
            dataIndex: 'postSalary',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'岗位绩效',
            align:"center",
            dataIndex: 'postPerformance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'保密补助',
            align:"center",
            dataIndex: 'confidentialAssistance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'交通及通讯',
            align:"center",
            dataIndex: 'trafficCommunication',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'全勤奖',
            align:"center",
            dataIndex: 'attendanceBonus',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'BM补助',
            align:"center",
            dataIndex: 'bmAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'管理津贴',
            align:"center",
            dataIndex: 'managementAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'奖励金',
            align:"center",
            dataIndex: 'incentivePayment',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'电脑补助',
            align:"center",
            dataIndex: 'computerAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'出差补助',
            align:"center",
            dataIndex: 'travelAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'误餐补助',
            align:"center",
            dataIndex: 'mealGrants',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'防暑降温补助',
            align:"center",
            dataIndex: 'heatstrokePrevention',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'冬季取暖补助',
            align:"center",
            dataIndex: 'heatingAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'独生子女补助',
            align:"center",
            dataIndex: 'oneChildAllowance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'托儿补助',
            align:"center",
            dataIndex: 'childcareSubsidies',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'商业保险补助',
            align:"center",
            dataIndex: 'commercialInsuranceSubsidy',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          // {
          //   title:'请假',
          //   align:"center",
          //   dataIndex: 'askForLeave',
          //   customRender: (t, item, index) => {
          //     return splitByNum(+t)
          //   }
          // },
          {
            title:'扣款',
            align:"center",
            dataIndex: 'deductMoney',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'税前总计',
            align:"center",
            dataIndex: 'beforeTotal',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'养老',
            align:"center",
            dataIndex: 'endowmentInsurance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'失业',
            align:"center",
            dataIndex: 'unemploymentInsurance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'医疗',
            align:"center",
            dataIndex: 'medicalInsurance',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'住房公积金',
            align:"center",
            dataIndex: 'housingProvidentFund',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'社保年检补缴',
            align:"center",
            dataIndex: 'socialSecurityCheck',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          // {
          //   title:'小计',
          //   align:"center",
          //   dataIndex: 'subtotal',
          //   customRender: (t, item, index) => {
          //     return splitByNum(+t)
          //   }
          // },
          {
            title:'个税',
            align:"center",
            dataIndex: 'payTaxes',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          {
            title:'其他扣款',
            align:"center",
            dataIndex: 'otherDeductMoney',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          // {
          //   title:'总计',
          //   align:"center",
          //   dataIndex: 'total',
          //   customRender: (t, item, index) => {
          //     return splitByNum(+t)
          //   }
          // },
          {
            title:'税后工资',
            align:"center",
            dataIndex: 'payrollCredit',
            customRender: (t, item, index) => {
              return splitByNum(+t)
            }
          },
          // {
          //   title:'代发补助',
          //   align:"center",
          //   dataIndex: 'payrollSubsidy',
          //   customRender: (t, item, index) => {
          //     return splitByNum(+t)
          //   }
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/wage/hfWageSalaryCount/list",
          delete: "/wage/hfWageSalaryCount/delete",
          deleteBatch: "/wage/hfWageSalaryCount/deleteBatch",
          exportXlsUrl: "/wage/hfWageSalaryCount/exportXls",
          importExcelUrl: "wage/hfWageSalaryCount/importExcel",
          count: '/wage/hfWageSalaryCount/count',

        },
        dictOptions:{},
        superFieldList:[],
        queryModel:true
      }
    },
    created() {

    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      moment,
      handleCountOk() {
        getAction(this.url.count, { selectedMonth: this.selectedMonth }).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.countVisible = false
          } else {
            this.$message.error(res.message)
          }
        })
      },
      monthChange(date) {
        this.selectedMonth = moment(date).format('YYYY-MM')
      },
      handleCountCancel() {
        this.countVisible = false
      },
      handleCount() {
        this.countVisible = true
      },
      initDictConfig(){
      },
      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.salaryTime_begin=dateString[0];
        this.queryParam.salaryTime_end=dateString[1];

      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>